#ifndef _TAGFS_NODE_H_
#define _TAGFS_NODE_H_

#include <list>
#include <stdint.h>

class TagFS_Node
{
	public:
		struct nodeRange
		{
			uint64_t start;
			uint64_t length;
			bool operator<  (nodeRange r);
			bool operator>  (nodeRange r);
			bool operator== (nodeRange r);
		};
		
		void init(FILE*, uint8_t, uint16_t, uint64_t);
		uint16_t getSize();
		uint64_t getAll();
		uint64_t getUsed();

		std::pair<uint64_t, int> read(uint64_t, char*);
		std::pair<uint64_t, int> write(uint64_t, const char*, bool);
		int write(uint64_t, const char*);

		static void cleanup(std::list<nodeRange>*);
		uint64_t reserve();
		void     reserve(uint64_t);
		void     reserve(std::list<uint64_t>);

		std::list<uint64_t> getList(uint64_t);

		void free(uint64_t);
		void free(std::list<uint64_t>);

	private:
		FILE* fs;
		uint8_t offset;
		uint16_t nodeSize;
		uint64_t maxNodes;
		std::list<nodeRange> usedNodes;
};

#endif
